package com.oracle.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.compents.PageResult;
import com.oracle.mapper.PhVideoMapper;
import com.oracle.pojo.PhVideo;
import com.oracle.pojo.PhVideoExample;
import com.oracle.pojo.PhVideoExample.Criteria;
import com.oracle.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class VideoServiceImpl implements VideoService {

	@Autowired
	private PhVideoMapper videoMapper;

	/**
	 * 查询全部
	 */
	@Override
	public List<PhVideo> findAll() {
		return videoMapper.selecPhyExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<PhVideo> page=   (Page<PhVideo>) videoMapper.selecPhyExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(PhVideo video) {
		videoMapper.insert(video);
	}


	/**
	 * 修改
	 */
	@Override
	public void update(PhVideo video){
		videoMapper.updateByPrimaryKey(video);
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public PhVideo findOne(Integer id){
		return videoMapper.selecPhyPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] ids) {
		for(Integer id:ids){
			videoMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(PhVideo video, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);

		PhVideoExample example=new PhVideoExample();
		Criteria criteria = example.createCriteria();

		if(video!=null){
						if(video.getVideourl()!=null && video.getVideourl().length()>0){
				criteria.andVideourlLike("%"+video.getVideourl()+"%");
			}			if(video.getVideotitle()!=null && video.getVideotitle().length()>0){
				criteria.andVideotitleLike("%"+video.getVideotitle()+"%");
			}			if(video.getCreatetime()!=null && video.getCreatetime().length()>0){
				criteria.andCreatetimeLike("%"+video.getCreatetime()+"%");
			}			if(video.getUname()!=null && video.getUname().length()>0){
				criteria.andUnameLike("%"+video.getUname()+"%");
			}			if(video.getVideodesc()!=null && video.getVideodesc().length()>0){
				criteria.andVideodescLike("%"+video.getVideodesc()+"%");
			}			if(video.getVideophoto()!=null && video.getVideophoto().length()>0){
				criteria.andVideophotoLike("%"+video.getVideophoto()+"%");
			}
		}

		Page<PhVideo> page= (Page<PhVideo>)videoMapper.selecPhyExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}

}
